/*
 * @Description: 原文挂接
 * @Author: Rfan
 * @Date: 2022-05-04 19:07:54
 * @LastEditTime: 2022-07-18 15:26:24
 */

import { useEffect, useMemo, useState } from 'react';
import { Button, Col, Form, Modal, Row, Select } from 'antd';
import { useLevelTableContext } from '@/components/LevelTable/contexts/LevelTableContext';
import type { FC } from 'react';
import type { ICommonDialog } from '@/interfaces/global';
import FieldMap from '@/components/LevelTable/componentes/dialogs/FieldMap';
import { breakUpArchivesMethod, IBreakUpArchivesParams } from '@/api/archives/scattered';
import { ICoordinate } from '@/interfaces/global';

interface ISeparateDialogProps extends ICommonDialog {}

const SeparateDialog: FC<ISeparateDialogProps> = (props) => {
  const { visible, onClose } = props;
  const { selectItems, baseInfo, dbName } = useLevelTableContext();
  const [form] = Form.useForm();

  const [mapVisible, setMapVisible] = useState(false);

  useEffect(() => {
    if (visible) {
      //
    }
  }, [visible]);

  const onCancel = () => {
    onClose();
  };

  /**
   * @description: 保存表单方法
   */
  const onFinish = (vals: any) => {
    const params: IBreakUpArchivesParams = {
      fromDb: dbName,
      coordinate: {
        atCode: baseInfo.atCode,
        atType: baseInfo.atType,
        level: baseInfo.level
      },
      movingEntryInfo: {
        entryIdList: selectItems,
        searchCondition: ''
      }
    };
    breakUpArchivesMethod(params).then(() => {
      onClose();
    });
  };

  return (
    <Modal
      title="拆离"
      visible={visible}
      width={500}
      destroyOnClose
      onCancel={onCancel}
      footer={[
        <Button key="close" onClick={onCancel}>
          取消
        </Button>,
        <Button
          key="export"
          type="primary"
          onClick={() => {
            form.submit();
          }}
        >
          拆离
        </Button>
      ]}
    >
      <Form
        form={form}
        name="FolderForm"
        labelCol={{ span: 7 }}
        wrapperCol={{ span: 14 }}
        // initialValues={{ path: data }}
        autoComplete="off"
        onFinish={onFinish}
      >
        <Form.Item label="档案类型">
          <Row justify="space-between">
            <Col>
              <Form.Item noStyle>文书档案</Form.Item>
            </Col>
            <Col>
              <Form.Item noStyle>您已选择{selectItems.length}个条目进行拆离</Form.Item>
            </Col>
          </Row>
        </Form.Item>
        {/* <Form.Item label="移出到散文件库"> */}
        {/*  <Select></Select> */}
        {/* </Form.Item> */}
      </Form>
    </Modal>
  );
};

export default SeparateDialog;
